package com.ruoyi.web.controller.net;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.net.domain.*;
import com.ruoyi.net.netconf.Device;
import com.ruoyi.net.netconf.util.DeviceManager;
import com.ruoyi.net.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 网元-业务-mtnclient-fgController
 *
 * @author net
 * @date 2024-11-17
 */
@Api(tags = "网元-业务-mtnclient-fg")
@RestController
@RequestMapping("/element/busi/mtnclient/fg")
public class ElementBusiMtnclientFgController extends BaseController {
    @Autowired
    private IElementBusiMtnclientFgService elementBusiMtnclientFgService;

    @Autowired
    private IBusiElementStatusService busiElementStatusService;
    @Autowired
    private DeviceManager deviceManager;

    @Autowired
    private INetElementService netElementService;

    @Autowired
    private IBusiMtnChannelRouteTableService busiMtnChannelRouteTableService;

    @Autowired
    private IBusiMtnChannelService busiMtnChannelService;

    @Autowired
    private IElementPortModeService elementPortModeService;

    @Autowired
    private IBusiMtnChannelCrossService busiMtnChannelCrossService;

    @Autowired
    private IElementPortMtnEvthService elementPortMtnEvthService;

    @Autowired
    private IBusiMtnChannelSubclientService busiMtnChannelSubclientService;

    @Autowired
    private IElementBusiMtnChannelOamService busiMtnChannelOamService;

    /**
     * 查询网元-业务-mtnclient-fg列表
     */
    @ApiOperation(value = "查询网元-业务-mtnclient-fg列表", httpMethod = "GET")
    @GetMapping("/list")
    public TableDataInfo list(ElementBusiMtnclientFg elementBusiMtnclientFg) {
        startPage();
        elementBusiMtnclientFg.setOrder("desc");
        List<ElementBusiMtnclientFgVo> list = elementBusiMtnclientFgService.selectElementBusiMtnclientFgList(elementBusiMtnclientFg);
        return getDataTable(list);
    }

    /**
     * 导出网元-业务-mtnclient-fg列表
     */
    @ApiOperation(value = "导出网元-业务-mtnclient-fg列表", httpMethod = "POST")
    //    @PreAuthorize("@ss.hasPermi('system:fg:export')")
    @Log(title = "网元-业务-mtnclient-fg", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElementBusiMtnclientFg elementBusiMtnclientFg) {
        List<ElementBusiMtnclientFgVo> list = elementBusiMtnclientFgService.selectElementBusiMtnclientFgList(elementBusiMtnclientFg);
        ExcelUtil<ElementBusiMtnclientFgVo> util = new ExcelUtil<>(ElementBusiMtnclientFgVo.class);
        util.exportExcel(response, list, "网元-业务-mtnclient-fg数据");
    }

    /**
     * 获取网元-业务-mtnclient-fg详细信息
     */
    @ApiOperation(value = "获取网元-业务-mtnclient-fg详细信息", httpMethod = "GET")
    //    @PreAuthorize("@ss.hasPermi('system:fg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(elementBusiMtnclientFgService.selectElementBusiMtnclientFgById(id));
    }

    /**
     * 新增网元-业务-mtnclient-fg
     */
    @ApiOperation(value = "新增网元-业务-mtnclient-fg", httpMethod = "POST")
    //    @PreAuthorize("@ss.hasPermi('system:fg:add')")
    @Log(title = "网元-业务-mtnclient-fg", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElementBusiMtnclientFg elementBusiMtnclientFg) {
        return toAjax(elementBusiMtnclientFgService.insertElementBusiMtnclientFg(elementBusiMtnclientFg));
    }

    /**
     * 修改网元-业务-mtnclient-fg
     */
    @ApiOperation(value = "修改网元-业务-mtnclient-fg", httpMethod = "PUT")
    //    @PreAuthorize("@ss.hasPermi('system:fg:edit')")
    @Log(title = "网元-业务-mtnclient-fg", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElementBusiMtnclientFg elementBusiMtnclientFg) {
        return toAjax(elementBusiMtnclientFgService.updateElementBusiMtnclientFg(elementBusiMtnclientFg));
    }

    /**
     * 删除网元-业务-mtnclient-fg
     */
    @ApiOperation(value = "删除网元-业务-mtnclient-fg", httpMethod = "DELETE")
    //    @PreAuthorize("@ss.hasPermi('system:fg:remove')")
    @Log(title = "网元-业务-mtnclient-fg", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(elementBusiMtnclientFgService.deleteElementBusiMtnclientFgByIds(ids));
    }

    /**
     * 批量激活设备
     */
    @ApiOperation(value = "业务管理mtn界面批量激活设备", httpMethod = "GET")
    @GetMapping(value = "/activateAll/{mtnChannelId}")
    @Log(title = "批量激活设备", businessType = BusinessType.UPDATE)
    public AjaxResult activateDeviceAll(@PathVariable("mtnChannelId") String mtnChannelId) {
        ElementBusiMtnclientFg elementBusiMtnclientFg = new ElementBusiMtnclientFg();
        elementBusiMtnclientFg.setMtnChannelId(mtnChannelId);
        //只激活未激活数据
        elementBusiMtnclientFg.setStatus("0");
        List<ElementBusiMtnclientFgVo> fgList = elementBusiMtnclientFgService.selectElementBusiMtnclientFgList(elementBusiMtnclientFg);
        return toAjax(batchActivate(fgList, mtnChannelId));
    }

    /**
     * 批量激活设备
     */
    private int batchActivate(List<ElementBusiMtnclientFgVo> fgList, String mtnChannelId) {
        int result = 0;
        BusiMtnChannel busiMtnChannel = busiMtnChannelService.selectBusiMtnChannelById(mtnChannelId);
        BusiMtnChannelXmlVo busiMtnChannelXmlVo = new BusiMtnChannelXmlVo();
        busiMtnChannelXmlVo.setStatus("1");
        busiMtnChannelXmlVo.setProtectType(busiMtnChannel.getProtectType());

        BusiElementStatus busiElementStatus = new BusiElementStatus();
        busiElementStatus.setBusiId(mtnChannelId);
        busiElementStatus.setStatus("1");
        busiElementStatus.setUpdateBy(SecurityUtils.getUsername());

        ElementBusiMtnclientFg clientFgUpdateParam = new ElementBusiMtnclientFg();
        clientFgUpdateParam.setMtnChannelId(mtnChannelId);
        clientFgUpdateParam.setStatus("1");

        BusiMtnChannelCross busiMtnChannelCross = new BusiMtnChannelCross();
        busiMtnChannelCross.setMtnChannelId(mtnChannelId);
        busiMtnChannelCross.setStatus("1");

        BusiElementStatus busiElementStatus2 = new BusiElementStatus();
        busiElementStatus2.setBusiId(mtnChannelId);

        for (ElementBusiMtnclientFgVo mtnclientFgVo : fgList) {
            ElementBusiMtnclientFg elementBusiMtnclientFg = elementBusiMtnclientFgService.selectElementBusiMtnclientFgById(mtnclientFgVo.getId());
            if (sendXml(busiMtnChannelXmlVo, elementBusiMtnclientFg)) {
                //同步业务设备状态
                busiElementStatus.setElementId(elementBusiMtnclientFg.getElementId());
                busiElementStatus.setUpdateTime(DateUtils.getNowDate());
                busiElementStatusService.updateBusiElementStatusByParams(busiElementStatus);

                clientFgUpdateParam.setElementId(elementBusiMtnclientFg.getElementId());
                clientFgUpdateParam.setUpdateTime(DateUtils.getNowDate());
                //更新fg状态
                elementBusiMtnclientFgService.updateElementBusiMtnclientFgStatusByEle(clientFgUpdateParam);
                //更新过站状态
                busiMtnChannelCross.setElementId(elementBusiMtnclientFg.getElementId());
                busiMtnChannelCrossService.updateBusiMtnChannelCrossStatusByParam(busiMtnChannelCross);
                //更新业务表状态  部分激活2/激活1

                List<BusiElementStatus> statusList2 = busiElementStatusService.selectBusiElementStatusList(busiElementStatus2);
                Optional<BusiElementStatus> max = statusList2.stream().max(Comparator.comparing(BusiElementStatus::getStatus));
                Optional<BusiElementStatus> min = statusList2.stream().min(Comparator.comparing(BusiElementStatus::getStatus));
                if (max.get().getStatus().equals(min.get().getStatus())) {
                    if ("0".equals(max.get().getStatus())) {
                        busiMtnChannel.setStatus("0");
                    } else {
                        busiMtnChannel.setStatus("1");
                    }
                } else {
                    busiMtnChannel.setStatus("2");
                }
                result = busiMtnChannelService.updateBusiMtnChannel(busiMtnChannel);
            } else {
                logger.info("mtn-业务管理批量激活-单站激活失败");
            }
        }
        if(result>0){
            //如果批量激活成功，调用新增虚拟接口模式，虚拟纤
            busiMtnChannelService.insertVirtualInterface(mtnChannelId);
        }
        return result;
    }

    /**
     * 批量去激活设备
     *
     */
    @ApiOperation(value = "业务管理mtn界面批量去激活设备", httpMethod = "GET")
    @GetMapping(value = "/unActivateAll/{mtnChannelId}")
    @Log(title = "批量去激活设备", businessType = BusinessType.UPDATE)
    public AjaxResult unActivateDeviceAll(@PathVariable("mtnChannelId") String mtnChannelId) {
        ElementBusiMtnclientFg elementBusiMtnclientFg = new ElementBusiMtnclientFg();
        elementBusiMtnclientFg.setMtnChannelId(mtnChannelId);
        //只去激活激活数据
        elementBusiMtnclientFg.setStatus("1");
        List<ElementBusiMtnclientFgVo> fgList = elementBusiMtnclientFgService.selectElementBusiMtnclientFgList(elementBusiMtnclientFg);
        return toAjax(batchUnActivate(fgList, mtnChannelId));
    }

    /**
     * 批量去激活设备
     *
     */
    private int batchUnActivate(List<ElementBusiMtnclientFgVo> fgList, String mtnChannelId) {
        int result = 0;
        BusiMtnChannel busiMtnChannel = busiMtnChannelService.selectBusiMtnChannelById(mtnChannelId);
        BusiMtnChannelXmlVo busiMtnChannelXmlVo = new BusiMtnChannelXmlVo();
        busiMtnChannelXmlVo.setStatus("0");
        busiMtnChannelXmlVo.setProtectType(busiMtnChannel.getProtectType());

        BusiElementStatus busiElementStatus = new BusiElementStatus();
        busiElementStatus.setBusiId(mtnChannelId);
        busiElementStatus.setStatus("0");
        busiElementStatus.setUpdateBy(SecurityUtils.getUsername());

        ElementBusiMtnclientFg clientFgUpdateParam = new ElementBusiMtnclientFg();
        clientFgUpdateParam.setMtnChannelId(mtnChannelId);
        clientFgUpdateParam.setStatus("0");

        BusiMtnChannelCross busiMtnChannelCross = new BusiMtnChannelCross();
        busiMtnChannelCross.setMtnChannelId(mtnChannelId);
        busiMtnChannelCross.setStatus("0");

        BusiElementStatus busiElementStatus2 = new BusiElementStatus();
        busiElementStatus2.setBusiId(mtnChannelId);

        for (ElementBusiMtnclientFgVo fgVo : fgList) {
            ElementBusiMtnclientFg elementBusiMtnclientFg = elementBusiMtnclientFgService.selectElementBusiMtnclientFgById(fgVo.getId());
            if (sendXml(busiMtnChannelXmlVo, elementBusiMtnclientFg)) {
                //同步业务设备状态
                busiElementStatus.setElementId(elementBusiMtnclientFg.getElementId());
                busiElementStatus.setUpdateTime(DateUtils.getNowDate());
                busiElementStatusService.updateBusiElementStatusByParams(busiElementStatus);

                //更新fg状态
                clientFgUpdateParam.setElementId(elementBusiMtnclientFg.getElementId());
                elementBusiMtnclientFgService.updateElementBusiMtnclientFgStatusByEle(clientFgUpdateParam);
                //更新过站状态
                busiMtnChannelCross.setElementId(elementBusiMtnclientFg.getElementId());
                busiMtnChannelCrossService.updateBusiMtnChannelCrossStatusByParam(busiMtnChannelCross);
                //更新业务表状态  部分激活2/激活1
                List<BusiElementStatus> statusList = busiElementStatusService.selectBusiElementStatusList(busiElementStatus2);
                Optional<BusiElementStatus> max = statusList.stream().max(Comparator.comparing(BusiElementStatus::getStatus));
                Optional<BusiElementStatus> min = statusList.stream().min(Comparator.comparing(BusiElementStatus::getStatus));
                if (max.get().getStatus().equals(min.get().getStatus())) {
                    if ("0".equals(max.get().getStatus())) {
                        busiMtnChannel.setStatus("0");
                    } else {
                        busiMtnChannel.setStatus("1");
                    }
                } else {
                    busiMtnChannel.setStatus("2");
                }
                result = busiMtnChannelService.updateBusiMtnChannel(busiMtnChannel);
            } else {
                logger.info("mtn-业务管理批量激活-单站去激活失败");
            }
        }
        if(result>0){
            //如果批量去激活成功，调用新增虚拟接口模式，虚拟纤
            busiMtnChannelService.deleteVirtualInterface(mtnChannelId);
        }
        return result;
    }


    /**
     * 激活设备
     *
     */
    @ApiOperation(value = "client激活设备", httpMethod = "GET")
    @GetMapping(value = "/client/activate/{id}")
    @Log(title = "client激活设备", businessType = BusinessType.UPDATE)
    public AjaxResult activateDevice(@PathVariable("id") String id) {
        ElementBusiMtnclientFg elementBusiMtnclientFg = elementBusiMtnclientFgService.selectElementBusiMtnclientFgById(id);
        String mtnId = elementBusiMtnclientFg.getMtnChannelId();
        BusiMtnChannel busiMtnChannel = busiMtnChannelService.selectBusiMtnChannelById(mtnId);

        BusiMtnChannelXmlVo busiMtnChannelXmlVo = new BusiMtnChannelXmlVo();
        busiMtnChannelXmlVo.setStatus("1");
        busiMtnChannelXmlVo.setProtectType(busiMtnChannel.getProtectType());
        if (sendXml(busiMtnChannelXmlVo, elementBusiMtnclientFg)) {
            //同步业务设备状态
            BusiElementStatus busiElementStatus = new BusiElementStatus();
            busiElementStatus.setElementId(elementBusiMtnclientFg.getElementId());
            busiElementStatus.setBusiId(elementBusiMtnclientFg.getMtnChannelId());
            busiElementStatus.setStatus("1");
            busiElementStatus.setUpdateBy(SecurityUtils.getUsername());
            busiElementStatus.setUpdateTime(DateUtils.getNowDate());
            busiElementStatusService.updateBusiElementStatusByParams(busiElementStatus);
            ElementBusiMtnclientFg clientFgUpdateParam = new ElementBusiMtnclientFg();
            clientFgUpdateParam.setMtnChannelId(mtnId);
            clientFgUpdateParam.setStatus("1");
            clientFgUpdateParam.setElementId(elementBusiMtnclientFg.getElementId());
            //更新fg状态
            elementBusiMtnclientFgService.updateElementBusiMtnclientFgStatusByEle(clientFgUpdateParam);
            //更新过站状态
            BusiMtnChannelCross busiMtnChannelCross = new BusiMtnChannelCross();
            busiMtnChannelCross.setMtnChannelId(mtnId);
            busiMtnChannelCross.setElementId(elementBusiMtnclientFg.getElementId());
            busiMtnChannelCross.setStatus("1");
            busiMtnChannelCrossService.updateBusiMtnChannelCrossStatusByParam(busiMtnChannelCross);
            //更新业务表状态  部分激活2/激活1
            BusiElementStatus busiElementStatus2 = new BusiElementStatus();
            busiElementStatus2.setBusiId(mtnId);
            List<BusiElementStatus> statusList = busiElementStatusService.selectBusiElementStatusList(busiElementStatus2);
            Optional<BusiElementStatus> max = statusList.stream().max(Comparator.comparing(BusiElementStatus::getStatus));
            Optional<BusiElementStatus> min = statusList.stream().min(Comparator.comparing(BusiElementStatus::getStatus));
            if (max.get().getStatus().equals(min.get().getStatus())) {
                if ("0".equals(max.get().getStatus())) {
                    busiMtnChannel.setStatus("0");
                } else {
                    busiMtnChannel.setStatus("1");
                }
            } else {
                busiMtnChannel.setStatus("2");
            }
            return toAjax(busiMtnChannelService.updateBusiMtnChannel(busiMtnChannel));
        } else {
            return AjaxResult.error("激活设备失败");
        }
    }

    /**
     * 去激活设备
     *
     * @param id
     */
    @ApiOperation(value = "client去激活设备", httpMethod = "GET")
    @Log(title = "client去激活设备", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/client/unactivate/{id}")
    public AjaxResult unactivateDevice(@PathVariable("id") String id) {
        ElementBusiMtnclientFg elementBusiMtnclientFg = elementBusiMtnclientFgService.selectElementBusiMtnclientFgById(id);
        String mtnId = elementBusiMtnclientFg.getMtnChannelId();
        BusiMtnChannel busiMtnChannel = busiMtnChannelService.selectBusiMtnChannelById(mtnId);

        BusiMtnChannelXmlVo busiMtnChannelXmlVo = new BusiMtnChannelXmlVo();
        busiMtnChannelXmlVo.setStatus("0");
        busiMtnChannelXmlVo.setProtectType(busiMtnChannel.getProtectType());
        if (sendXml(busiMtnChannelXmlVo, elementBusiMtnclientFg)) {
            //同步业务设备状态
            BusiElementStatus busiElementStatus = new BusiElementStatus();
            busiElementStatus.setElementId(elementBusiMtnclientFg.getElementId());
            busiElementStatus.setBusiId(elementBusiMtnclientFg.getMtnChannelId());
            busiElementStatus.setStatus("0");
            busiElementStatus.setUpdateBy(SecurityUtils.getUsername());
            busiElementStatus.setUpdateTime(DateUtils.getNowDate());
            busiElementStatusService.updateBusiElementStatusByParams(busiElementStatus);
            ElementBusiMtnclientFg clientFgUpdateParam = new ElementBusiMtnclientFg();
            clientFgUpdateParam.setMtnChannelId(mtnId);
            clientFgUpdateParam.setStatus("0");
            clientFgUpdateParam.setElementId(elementBusiMtnclientFg.getElementId());
            //更新fg状态
            elementBusiMtnclientFgService.updateElementBusiMtnclientFgStatusByEle(clientFgUpdateParam);
            //更新过站状态
            BusiMtnChannelCross busiMtnChannelCross = new BusiMtnChannelCross();
            busiMtnChannelCross.setMtnChannelId(mtnId);
            busiMtnChannelCross.setElementId(elementBusiMtnclientFg.getElementId());
            busiMtnChannelCross.setStatus("0");
            busiMtnChannelCrossService.updateBusiMtnChannelCrossStatusByParam(busiMtnChannelCross);
            //更新业务表状态  部分激活2/激活1
            BusiElementStatus busiElementStatus2 = new BusiElementStatus();
            busiElementStatus2.setBusiId(mtnId);
            List<BusiElementStatus> statusList = busiElementStatusService.selectBusiElementStatusList(busiElementStatus2);
            Optional<BusiElementStatus> max = statusList.stream().max(Comparator.comparing(BusiElementStatus::getStatus));
            Optional<BusiElementStatus> min = statusList.stream().min(Comparator.comparing(BusiElementStatus::getStatus));
            if (max.get().getStatus().equals(min.get().getStatus())) {
                if ("0".equals(max.get().getStatus())) {
                    busiMtnChannel.setStatus("0");
                } else {
                    busiMtnChannel.setStatus("1");
                }
            } else {
                busiMtnChannel.setStatus("2");
            }
            return toAjax(busiMtnChannelService.updateBusiMtnChannel(busiMtnChannel));
        } else {
            return AjaxResult.error("去激活设备失败");
        }
    }

    /**
     * 发送xml到设备
     * tunnel :过站取subclient口  源宿取单站veth口
     * fgclient 取fgclient口
     * 时隙取sub时隙
     * 端口取路由对应的portId 查询接口配置terminalName
     *
     * @param busiMtnChannelXmlVo
     */
    private boolean sendXml(BusiMtnChannelXmlVo busiMtnChannelXmlVo, ElementBusiMtnclientFg mtnclientFg) {
        // TODO: 2024/11/22 待与设备联调
        NetElement netElement = netElementService.getCacheObject(mtnclientFg.getElementId());
        Device device = deviceManager.getDevice(netElement.getIp());
        if (device.isConnected()) {
            //校时
            validateTime();
            //前置条件  下保护组报文 或手动输入命令
            if ("无保护".equals(busiMtnChannelXmlVo.getProtectType())) {
                return sendNoProtectXml(busiMtnChannelXmlVo, mtnclientFg);
            } else {
                return sendProtectXml(busiMtnChannelXmlVo, mtnclientFg);
            }
        }
        return false;
    }

    /**
     * 下发校时报文
     * @return
     */
    private boolean validateTime() {
        // 手动设置系统时间
        boolean timeFlag = deviceManager.executeRPC("<set-systime xmlns=\"http://fiberhome.com/fhnw/yang/systemmanage/fos-system-oper\">" +
                "<date-time>" + DateUtils.getTime() + "</date-time>" +
                "<type>LOCAL</type>" +
                "</set-systime>");
            /*
            设置netconf 命令兼容模式 todo 2025-02-14 和小二沟通
             */
        deviceManager.editConfig("<ext-nms xmlns=\"http://fiberhome.com/fhnw/yang/fos-extension-nms\">" +
                "        <netconf-ignore-unknown-node>" +
                "          <enabled>enable</enabled>" +
                "        </netconf-ignore-unknown-node>" +
                "      </ext-nms>", "merge");
        logger.info("校时结果返回===================================================" + timeFlag);
        return timeFlag;
    }

    /**
     * 发送无保护xml
     *
     * @param busiMtnChannelXmlVo
     * @return
     */
    private boolean sendNoProtectXml(BusiMtnChannelXmlVo busiMtnChannelXmlVo, ElementBusiMtnclientFg mtnclientFg) {
        boolean isSend = false;
        if ("1".equals(mtnclientFg.getElementType()) || "2".equals(mtnclientFg.getElementType())) {
            //源宿  tunnel取fgclient口  时隙取sub时隙
            //1：busi_mtn_channel拿到channel主键  查询到开始网元（单设备）start_element  默认start
            BusiMtnChannelRouteTable busiMtnChannelRouteTable = new BusiMtnChannelRouteTable();
            busiMtnChannelRouteTable.setMtnChannelId(mtnclientFg.getMtnChannelId());
            busiMtnChannelRouteTable.setRouteDirection("1");//默认工作  正向
            List<BusiMtnChannelRouteListVoTable> busiMtnChannelRouteListVoTables = busiMtnChannelRouteTableService.selectBusiMtnChannelRouteTableList(busiMtnChannelRouteTable);
            //过滤当前网元路由信息
            List<BusiMtnChannelRouteListVoTable> routeInfos = busiMtnChannelRouteListVoTables.stream().filter(busiMtnChannelRouteListVoTable -> mtnclientFg.getElementId().equals(busiMtnChannelRouteListVoTable.getElementId())).collect(Collectors.toList());
            String portName = "";
            //取portName
            if (!CollectionUtils.isEmpty(routeInfos)) {
                ElementPortMode elementPortMode = elementPortModeService.selectElementPortModeById(routeInfos.get(0).getPortId());
                portName = elementPortMode.getPortName();
            }
            //取FgClientName
            String[] fgNames = mtnclientFg.getName().split("mtntunnel");
            //取单站veth口
            ElementPortMtnEvth singleEvth = new ElementPortMtnEvth();
            singleEvth.setMtnChannelId(mtnclientFg.getMtnChannelId());
            singleEvth.setElementId(mtnclientFg.getElementId());
            //正常就一条数据
            List<ElementPortMtnEvth> singleEvths = elementPortMtnEvthService.selectElementPortMtnEvthList(singleEvth);
            String singleEvthName = singleEvths.get(0).getTerminalName().split("mtnveth")[1];

            //取时隙
            BusiMtnChannelSubclient subclient = new BusiMtnChannelSubclient();
            subclient.setFgClientId(mtnclientFg.getId());
            subclient.setMtnChannelId(mtnclientFg.getMtnChannelId());
            List<BusiMtnChannelSubclient> subclientList = busiMtnChannelSubclientService.selectBusiMtnChannelSubclientList(subclient);
            String timeslot = subclientList.get(0).getTimeSlot();
            //源宿 激活
            if ("1".equals(busiMtnChannelXmlVo.getStatus())) {
                //1、生成fgclient口
                String xml1 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                                "<interfaces>" +
                                    "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                                    "<name>mtn-fgclient" + fgNames[1] + "</name>" +//端口名采用mtn-fgcient加序号的形式  取路由表端口名称
                                    "<type>MTN-FGCLIENT</type>" +//端口类型
                                    "<mtn-fgclient-ctrlinterface xmlns=\"http://fiberhome.com/fhnw/yang/interface/mtninterface/fos-mtnif-fgclientctrl\">" +
                                        "<work-mode>terminate</work-mode>" +//工作模式：过站取值transparent，源宿取值terminate
                                        "<fgclient-num>" + fgNames[1] + "</fgclient-num>" +//MTN FGClient Num配置,取值范围1-65534，要求同一条小颗粒业务两端fg Client Num相同
                                        "<fgclient-timeslot>" + "<if-name>" + portName + "</if-name>" +//时隙取sub
                                        "<fg-timeslot-str>" + timeslot + "</fg-timeslot-str>" +//????  fg client时隙配置，必选，字符串配置格式0-1,3-4,6 时隙从0开始编号
                                        "</fgclient-timeslot>" +
                                    "</mtn-fgclient-ctrlinterface>" +
                                    "</interface>" +
                                "</interfaces>" +
                            "</if>";
                logger.info("MTN FG-Client激活xml1为：{}", xml1);
                isSend = deviceManager.editConfig(xml1, "merge");
                logger.info("isSend===================================================" + isSend);
                String xml2 =   "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                                    "<interfaces>" +
                                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                                        "<name>flexe-tunnel" + singleEvthName + "</name>" +//源宿取单站veth口
                                        "<type>FLEXE-TUNNEL</type>" +
                                            "<flexetunnel-ctrlinterface xmlns=\"http://fiberhome.com/fhnw/yang/interface/flexeinterface/fos-flexeif-tunnel\">" +
                                            "<protect-type>none</protect-type>" +
                                            "<work-flexe-client>mtn-fgclient" + fgNames[1] + "</work-flexe-client>" +
                                            "</flexetunnel-ctrlinterface>" +
                                        "</interface>" +
                                    "</interfaces>" +
                                "</if>" +


                        "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                            "<interfaces>" +
                                "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                                    "<name>flexe-tunnel" + singleEvthName + "</name>" +
                                    "<type>FLEXE-TUNNEL</type>" +
                                    "<transport-layer xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-l2l3common\">layer-3-route" + "</transport-layer>" +
                                    "<ip xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-l2l3common\">";

                // 2025-07-17 invalid number, 判断 null 值
                if (StringUtils.isNotEmpty(singleEvths.get(0).getMaxFrameLen())) {
                    xml2 += "               <ipv4-mtu>" + singleEvths.get(0).getMaxFrameLen() + "</ipv4-mtu>";
                }
                // 2025-07-17 小二反馈问题，增加 ip 和 mask
                if (StringUtils.isNotEmpty(singleEvths.get(0).getIp()) && StringUtils.isNotEmpty(singleEvths.get(0).getMask())) {
                    xml2 += "               <ipv4-address-list>" +
                            "                <ipv4-address>" + singleEvths.get(0).getIp() + "/" + singleEvths.get(0).getMask() + "</ipv4-address>" +//取mtn veth口的ip  掩码
                            "                <secondry-use>mast</secondry-use>" +
                            "              </ipv4-address-list>";
                }
                xml2 +=              "</ip>" +
                                "</interface>" +
                            "</interfaces>" +
                        "</if>" +

                        " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "<interfaces>" + "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "<name>flexe-tunnel" + singleEvthName + "</name>" + "<type>FLEXE-TUNNEL</type>" + "<pdcn-cfg xmlns=\"http://fiberhome.com/fhnw/yang/systemmanage/fos-dcn\">" + "<enable>disable</enable>" + "</pdcn-cfg>" + "</interface>" + "</interfaces>" + "</if>";
                logger.info("MTN FG-Client激活xml2为：{}", xml2);
                isSend = deviceManager.editConfig(xml2, "merge");
                logger.info("isSend3===================================================" + isSend);
                //mpls使能
                String xml3 = "<mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                        "<mpls-te>" +
                        "<interface>" +
                        "<ifname>flexe-tunnel" + singleEvthName + "</ifname>" +//与mpls tunnel保持一致
                        "</interface>" +
                        "</mpls-te>" +
                        "</mpls>";
                logger.info("MTN FG-Client激活xml3为：{}", xml3);
                isSend = deviceManager.editConfig(xml3, "merge");
                logger.info("isSend4===================================================" + isSend);
            } else {
                //去激活
                //mpls使能
                String xml1 = "<mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                                "<mpls-te>" +
                                    "<interface nc:operation=\"remove\">" +
                                    "<ifname>flexe-tunnel" + singleEvthName + "</ifname>" +//与mpls tunnel保持一致
                                    "</interface>" +
                                "</mpls-te>" +
                            "</mpls>";
                logger.info("MTN FG-Client去激活xml1为：{}", xml1);
                isSend = deviceManager.editConfig(xml1, "merge");
                logger.info("isSend1===================================================" + isSend);
                String xml2 = " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                                    "<interfaces>" +
                                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                                        "<name>flexe-tunnel" + singleEvthName + "</name>" +
                                        "<type>FLEXE-TUNNEL</type>" +
                                        "<pdcn-cfg xmlns=\"http://fiberhome.com/fhnw/yang/systemmanage/fos-dcn\" nc:operation=\"remove\"/>" +
                                        "</interface>" +
                                    "</interfaces>" +
                                "</if>";
                logger.info("MTN FG-Client去激活xml2为：{}", xml2);
                isSend = deviceManager.editConfig(xml2, "merge");
                logger.info("isSend2===================================================" + isSend);
                String xml3 = " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                        "<interfaces>" +
                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                        "<name>flexe-tunnel" + singleEvthName + "</name>" +
                        "<type>FLEXE-TUNNEL</type>" +
                        "</interface>" +
                        "</interfaces>" +
                        "</if>";
                logger.info("MTN FG-Client去激活xml3为：{}", xml3);
                isSend = deviceManager.editConfig(xml3, "merge");
                logger.info("isSend2===================================================" + isSend);
                String xml4 = " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                        "<interfaces>" +
                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" +
                        "<name>flexe-tunnel" + singleEvthName + "</name>" +
                        "<type>FLEXE-TUNNEL</type>" +
                        "</interface>" +
                        "</interfaces>" +
                        "</if>";
                logger.info("MTN FG-Client去激活xml4为：{}", xml4);
                isSend = deviceManager.editConfig(xml4, "merge");
                logger.info("isSend4===================================================" + isSend);

                String xml5 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                        "<interfaces>" +
                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" +
                        "<name>mtn-fgclient" + fgNames[1] + "</name>" +//端口名采用mtn-fgcient加序号的形式  取路由表端口名称
                        "<type>MTN-FGCLIENT</type>" +//端口类型
                        "</interface>" +
                        "</interfaces>" +
                        "</if>";
                logger.info("MTN FG-Client去激活xml5为：{}", xml5);
                isSend = deviceManager.editConfig(xml5, "merge");
                logger.info("isSend5===================================================" + isSend);
            }
        } else {
            //过站  tunnel取fgclient口
            //1：busi_mtn_channel拿到channel主键  查询到开始网元（单设备）start_element  默认start
            BusiMtnChannelRouteTable busiMtnChannelRouteTable = new BusiMtnChannelRouteTable();
            //过站网元
            busiMtnChannelRouteTable.setElementId(mtnclientFg.getElementId());
            busiMtnChannelRouteTable.setMtnChannelId(mtnclientFg.getMtnChannelId());
            busiMtnChannelRouteTable.setRouteDirection("1");//默认正向  工作
            List<BusiMtnChannelRouteListVoTable> routeInfos = busiMtnChannelRouteTableService.selectBusiMtnChannelRouteTableList(busiMtnChannelRouteTable);
            //获取路由信息取portName、和时隙粒度
            //获取fgclient信息
            ElementBusiMtnclientFg elementBusiMtnclientFg = new ElementBusiMtnclientFg();
            elementBusiMtnclientFg.setMtnChannelId(mtnclientFg.getMtnChannelId());
            elementBusiMtnclientFg.setElementId(mtnclientFg.getElementId());
            //正常有两条路由信息  取clientNum
            List<ElementBusiMtnclientFgVo> elementBusiMtnclientFgs = elementBusiMtnclientFgService.selectElementBusiMtnclientFgList(elementBusiMtnclientFg);

            BusiMtnChannelSubclient subclient = new BusiMtnChannelSubclient();
            subclient.setFgClientId(mtnclientFg.getId());
            subclient.setMtnChannelId(mtnclientFg.getMtnChannelId());
            //按照创建时间升序  2条  工作 和保护
            List<BusiMtnChannelSubclient> subclientList = busiMtnChannelSubclientService.selectBusiMtnChannelSubclientList(subclient);


            String endPoint1Name = subclientList.get(0).getClientPortName().split("XGE/mtn-fgclient")[1];
            String endPoint2Name = subclientList.get(1).getClientPortName().split("XGE/mtn-fgclient")[1];

            //取cross信息 正常就一条数据
            BusiMtnChannelCross busiMtnChannelCross = new BusiMtnChannelCross();
            busiMtnChannelCross.setMtnChannelId(mtnclientFg.getMtnChannelId());
            List<BusiMtnChannelCrossListVo> busiMtnChannelCrossListVos = busiMtnChannelCrossService.selectBusiMtnChannelCrossList(busiMtnChannelCross);


            //激活
            if ("1".equals(busiMtnChannelXmlVo.getStatus())) {
                //===============================================fgclient====================================
                //正常有两条路由信息  取portName
                if (!CollectionUtils.isEmpty(routeInfos)) {
                    for (int i = 0; i < routeInfos.size(); i++) {
                        ElementPortMode elementPortMode = elementPortModeService.selectElementPortModeById(routeInfos.get(i).getPortId());
                        String portName = elementPortMode.getPortName();
                        String timeSlot = subclientList.get(i).getTimeSlot();
                        String fgClientName = subclientList.get(i).getClientPortName().split("XGE/mtn-fgclient")[1];
                        String fgClientNum = subclientList.get(i).getFgClientNum();

                        String actCrossXml = "  <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "        <interfaces>" + "          <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "            <name>mtn-fgclient" + fgClientName + "</name>" +//端口名采用mtn-fgcient加序号的形式
                                "            <type>MTN-FGCLIENT</type>" +//端口类型
                                "            <mtn-fgclient-ctrlinterface xmlns=\"http://fiberhome.com/fhnw/yang/interface/mtninterface/fos-mtnif-fgclientctrl\">" + "              <work-mode>transparent</work-mode>" +//工作模式：过站取值transparent，源宿取值terminate
                                "              <fgclient-num>" + fgClientNum + "</fgclient-num>" +//MTN FGClient Num配置,取值范围1-65534，要求同一条小颗粒业务两端fg Client Num相同
                                "              <fgclient-timeslot>" + "                <if-name>" + portName + "</if-name>" +//关键字，时隙成员接口
                                "                <fg-timeslot-str>" + timeSlot + "</fg-timeslot-str>" +//fg client时隙配置，必选，字符串配置格式0-1,3-4,6 时隙从0开始编号
                                "              </fgclient-timeslot>" + "            </mtn-fgclient-ctrlinterface>" + "          </interface>" + "        </interfaces>" + "      </if>";
                        logger.info("MTN FG-Client过站激活actCrossXml为：{}", actCrossXml);
                        isSend = deviceManager.editConfig(actCrossXml, "merge");
                        logger.info("isSend===================================================" + isSend);

                    }
                    //===============================================tunnel====================================
                    for (int i = 0; i < subclientList.size(); i++) {
                        String[] mtntunnels = subclientList.get(i).getClientPortName().split("XGE/mtn-fgclient");
                        String actCrossXml2 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "<interfaces>" + "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "<name>flexe-tunnel" + mtntunnels[1] + "</name>" +//flexe-tunnel加上序号
                                "<type>FLEXE-TUNNEL</type>" + "<flexetunnel-ctrlinterface xmlns=\"http://fiberhome.com/fhnw/yang/interface/flexeinterface/fos-flexeif-tunnel\">" + "<protect-type>none</protect-type>" + "<work-flexe-client>mtn-fgclient" + mtntunnels[1] + "</work-flexe-client>" + "</flexetunnel-ctrlinterface>" + "</interface>" + "</interfaces>" + "</if>";
                        logger.info("MTN FG-Client过站激活actCrossXml2为：{}", actCrossXml2);
                        isSend = deviceManager.editConfig(actCrossXml2, "merge");
                        logger.info("isSend===================================================" + isSend);
                    }
                    //===============================================cross====================================


                    String actCrossXml3 = "  <flexexc xmlns=\"http://fiberhome.com/fhnw/yang/transmissionservice/fos-flexeconnection\">" + "    <cross-connects>" + "      <cross-connect>" + "        <cross-connect-name>" + busiMtnChannelCrossListVos.get(0).getCrossName() + "</cross-connect-name>" + "        <endpoint1-name>flexe-tunnel" + endPoint1Name + "</endpoint1-name>" + "        <endpoint2-name>flexe-tunnel" + endPoint2Name + "</endpoint2-name>" + "      </cross-connect>" + "    </cross-connects>" + "  </flexexc>";
                    logger.info("MTN FG-Client过站激活actCrossXml3为：{}", actCrossXml3);
                    isSend = deviceManager.editConfig(actCrossXml3, "merge");
                    logger.info("isSend===================================================" + isSend);
                }
            } else {
                //===============================================cross====================================

                //去激活
                String inActCrossXml3 = "<flexexc xmlns=\"http://fiberhome.com/fhnw/yang/transmissionservice/fos-flexeconnection\">" + "    <cross-connects>" + "      <cross-connect nc:operation=\"remove\">" + "        <cross-connect-name>" + busiMtnChannelCrossListVos.get(0).getCrossName() + "</cross-connect-name>" + "        <endpoint1-name>flexe-tunnel" + endPoint1Name + "</endpoint1-name>" + "        <endpoint2-name>flexe-tunnel" + endPoint2Name + "</endpoint2-name>" + "      </cross-connect>" + "    </cross-connects>" + "  </flexexc>";
                logger.info("MTN FG-Client过站激活actCrossXml3为：{}", inActCrossXml3);
                isSend = deviceManager.editConfig(inActCrossXml3, "merge");
                logger.info("isSend===================================================" + isSend);
                //===============================================tunnel====================================

                for (int j = 0; j < subclientList.size(); j++) {
                    String[] mtntunnels = subclientList.get(j).getClientPortName().split("XGE/mtn-fgclient");
                    String inActCrossXml5 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "<interfaces>" + "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" + "<name>flexe-tunnel" + mtntunnels[1] + "</name>" +//flexe-tunnel加上序号
                            "<type>FLEXE-TUNNEL</type>" + "</interface>" + "</interfaces>" + "</if>";
                    logger.info("MTN FG-Client过站激活actCrossXml5为：{}", inActCrossXml5);
                    isSend = deviceManager.editConfig(inActCrossXml5, "merge");
                    logger.info("isSend===================================================" + isSend);
                }
                for (int j = 0; j < elementBusiMtnclientFgs.size(); j++) {
                    String[] mtntunnels = subclientList.get(j).getClientPortName().split("XGE/mtn-fgclient");
                    String inActCrossXml6 = "  <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "        <interfaces>" + "          <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "            <name>mtn-fgclient" + mtntunnels[1] + "</name>" +//端口名采用mtn-fgcient加序号的形式
                            "            <type>MTN-FGCLIENT</type>" +//端口类型
                            "          </interface>" + "        </interfaces>" + "      </if>";
                    logger.info("MTN FG-Client过站激活inActCrossXml6为：{}", inActCrossXml6);
                    isSend = deviceManager.editConfig(inActCrossXml6, "merge");
                    logger.info("isSend===================================================" + isSend);
                }
            }
        }
        return isSend;
    }

    /**
     * 发送有保护xml
     *
     * @param busiMtnChannelXmlVo
     * @return true/false
     */
    private boolean sendProtectXml(BusiMtnChannelXmlVo busiMtnChannelXmlVo, ElementBusiMtnclientFg mtnclientFg) {
        boolean isSend = false;
        if ("1".equals(mtnclientFg.getElementType()) || "2".equals(mtnclientFg.getElementType())) {
            //源宿
            BusiMtnChannelRouteTable busiMtnChannelRouteTable = new BusiMtnChannelRouteTable();
            busiMtnChannelRouteTable.setMtnChannelId(mtnclientFg.getMtnChannelId());
            busiMtnChannelRouteTable.setRouteDirection("1");//默认工作  正向
            List<BusiMtnChannelRouteListVoTable> busiMtnChannelRouteListVoTables = busiMtnChannelRouteTableService.selectBusiMtnChannelRouteTableList(busiMtnChannelRouteTable);
            //过滤当前网元路由信息  有保护  应该是两条  此结果顺序需要与fg保持一致即可  第一条为工作 第二条为保护
            List<BusiMtnChannelRouteListVoTable> routeInfos = busiMtnChannelRouteListVoTables.stream().filter(busiMtnChannelRouteListVoTable -> mtnclientFg.getElementId().equals(busiMtnChannelRouteListVoTable.getElementId())).collect(Collectors.toList());

            //sub表取Client端口 FgClientNum 时隙
            BusiMtnChannelSubclient subclient = new BusiMtnChannelSubclient();
            subclient.setFgClientId(mtnclientFg.getId());
            subclient.setMtnChannelId(mtnclientFg.getMtnChannelId());
            //按照创建时间升序  两条  1工作 2保护
            List<BusiMtnChannelSubclient> subclientList = busiMtnChannelSubclientService.selectBusiMtnChannelSubclientList(subclient);

            String workFgName = "";
            String proFgName = "";

            //取单站veth口
            ElementPortMtnEvth singleEvth = new ElementPortMtnEvth();
            singleEvth.setMtnChannelId(mtnclientFg.getMtnChannelId());
            singleEvth.setElementId(mtnclientFg.getElementId());
            //正常就一条数据
            List<ElementPortMtnEvth> singleEvths = elementPortMtnEvthService.selectElementPortMtnEvthList(singleEvth);
            String singleEvthName = singleEvths.get(0).getTerminalName().split("mtnveth")[1];
            String maxFrameLen = singleEvths.get(0).getMaxFrameLen();
            //源宿 激活
            if ("1".equals(busiMtnChannelXmlVo.getStatus())) {
                for (int i = 0; i < routeInfos.size(); i++) {
                    ElementPortMode elementPortMode = elementPortModeService.selectElementPortModeById(routeInfos.get(i).getPortId());
                    String portName = elementPortMode.getPortName();
                    //todo 取subclient fglient值
                    String timeSlot = "";
                    String fgClientName = "";
                    String fgClientNum = "";
                    if (i == 0) {
                        fgClientName = subclientList.get(0).getClientPortName().split("XGE/mtn-fgclient")[1];
                        fgClientNum = subclientList.get(0).getFgClientNum();
                        timeSlot = subclientList.get(0).getTimeSlot();
                    } else {
                        fgClientName = subclientList.get(1).getClientPortName().split("XGE/mtn-fgclient")[1];
                        fgClientNum = subclientList.get(1).getFgClientNum();
                        timeSlot = subclientList.get(1).getTimeSlot();
                    }

                    String proActXml = "  <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "        <interfaces>" + "          <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "            <name>mtn-fgclient" + fgClientName + "</name>" +//端口名采用mtn-fgcient加序号的形式
                            "            <type>MTN-FGCLIENT</type>" +//端口类型
                            "            <mtn-fgclient-ctrlinterface xmlns=\"http://fiberhome.com/fhnw/yang/interface/mtninterface/fos-mtnif-fgclientctrl\">" + "              <work-mode>terminate</work-mode>" +//工作模式：过站取值transparent，源宿取值terminate
                            "              <fgclient-num>" + fgClientNum + "</fgclient-num>" +//MTN FGClient Num配置,取值范围1-65534，要求同一条小颗粒业务两端fg Client Num相同
                            "              <fgclient-timeslot>" + "                <if-name>" + portName + "</if-name>" +//关键字，时隙成员接口
                            "                <fg-timeslot-str>" + timeSlot + "</fg-timeslot-str>" +//fg client时隙配置，必选，字符串配置格式0-1,3-4,6 时隙从0开始编号
                            "              </fgclient-timeslot>" + "            </mtn-fgclient-ctrlinterface>" + "          </interface>" + "        </interfaces>" + "      </if>";
                    logger.info("MTN FG-Client有保护源宿激活proActXml为：{}", proActXml);
                    isSend = deviceManager.editConfig(proActXml, "merge");
                    logger.info("isSend===================================================" + isSend);

                }
                //查询oam信息  工作、保护
                ElementBusiMtnChannelOam elementBusiMtnChannelOam = new ElementBusiMtnChannelOam();
                elementBusiMtnChannelOam.setMtnChannelId(mtnclientFg.getMtnChannelId());
                elementBusiMtnChannelOam.setElementId(mtnclientFg.getElementId());

                List<ElementBusiMtnChannelOamListVo> oamLists = busiMtnChannelOamService.selectElementBusiMtnChannelOamList(elementBusiMtnChannelOam);
                String fgName = "";
                for (int i = 0; i < oamLists.size(); i++) {
                    if (i == 0) {
                        fgName = subclientList.get(0).getClientPortName().split("XGE/mtn-fgclient")[1];
                        workFgName = subclientList.get(0).getClientPortName().split("XGE/mtn-fgclient")[1];
                    } else {
                        fgName = subclientList.get(1).getClientPortName().split("XGE/mtn-fgclient")[1];
                        proFgName = subclientList.get(1).getClientPortName().split("XGE/mtn-fgclient")[1];
                    }
                    String oamXml = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "    <interfaces>" + "      <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "        <name>mtn-fgclient" + fgName + "</name>" + "        <type>MTN-FGCLIENT</type>" + "        <flexe-oam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-flexeoam\">" + "          <bas-enable>enable</bas-enable>" + "          <bas-period>1280</bas-period>" + "          <aps-enable>disable</aps-enable>" + "          <cv-sapi>flexe_fiberhome</cv-sapi>" + "          <cv-dapi>flexe_fiberhome</cv-dapi>" + "          <cv-enable>disable</cv-enable>" + "          <cv-period>10s</cv-period>" + "          <cs-enable>disable</cs-enable>" + "          <cs-peorid>10s</cs-peorid>" + "          <dm1-enable>disable</dm1-enable>" + "          <dm1-period>10s</dm1-period>" + "          <dm2-enable>disable</dm2-enable>" + "          <dm2-period>10s</dm2-period>" + "          <uni-slot>0</uni-slot>" + "          <uni-port>0</uni-port>" + "          <sf-alarm-enable>disable</sf-alarm-enable>" + "          <sf-alarm-threshold-x>1</sf-alarm-threshold-x>" + "          <sf-alarm-threshold-y>7</sf-alarm-threshold-y>" + "          <sf-resume-threshold-x>1</sf-resume-threshold-x>" + "          <sf-resume-threshold-y>8</sf-resume-threshold-y>" + "          <sd-alarm-enable>disable</sd-alarm-enable>" + "          <sd-alarm-threshold-x>1</sd-alarm-threshold-x>" + "          <sd-alarm-threshold-y>7</sd-alarm-threshold-y>" + "          <sd-resume-threshold-x>1</sd-resume-threshold-x>" + "          <sd-resume-threshold-y>8</sd-resume-threshold-y>" + "          <interval-second>20</interval-second>" + "          <two-way-dm-upper-limit>0</two-way-dm-upper-limit>" + "          <two-way-dm-lower-limit>0</two-way-dm-lower-limit>" + "          <two-way-dm-static-delay>0</two-way-dm-static-delay>" + "          <two-way-dm-sampling-enable>disable</two-way-dm-sampling-enable>" + "          <two-way-dm-sampling-period>30</two-way-dm-sampling-period>" + "        </flexe-oam>" + "      </interface>" + "    </interfaces>" + "  </if>";
                    logger.info("MTN FG-Client有保护源宿激活oamXml为：{}", oamXml);
                    isSend = deviceManager.editConfig(oamXml, "merge");
                    logger.info("isSend===================================================" + isSend);
                }

                String proActXml5 = "  <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                                    "    <interfaces>" +
                        "      <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                        "        <name>flexe-tunnel" + singleEvthName + "</name>" +
                        "        <type>FLEXE-TUNNEL</type>" +
                        "        <flexetunnel-ctrlinterface xmlns=\"http://fiberhome.com/fhnw/yang/interface/flexeinterface/fos-flexeif-tunnel\">" +
                        "          <protect-type>flexe-1p1</protect-type>" +
                        "          <work-flexe-client>mtn-fgclient" + workFgName + "</work-flexe-client>" +
                        "          <protect-flexe-client>mtn-fgclient" + proFgName + "</protect-flexe-client>" +
                        "          <switch-mode>dual-ended</switch-mode>" +
                        "          <revertive-mode>revertive</revertive-mode>" +
                        "          <wtr>5</wtr>" +
                        "          <holdoff-time>0</holdoff-time>" +
                        "          <interdict-time>0</interdict-time>" +
                        "        </flexetunnel-ctrlinterface>" +
                        "      </interface>" +
                        "    </interfaces>" +
                        "  </if>";
                logger.info("MTN FG-Client有保护源宿激活proActXml5为：{}", proActXml5);
                isSend = deviceManager.editConfig(proActXml5, "merge");
                logger.info("isSend===================================================" + isSend);

                String proActXml6 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "        <interfaces>" + "          <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "            <name>flexe-tunnel" + singleEvthName + "</name>" + "            <type>FLEXE-TUNNEL</type>" + "            <transport-layer xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-l2l3common\">layer-3-route</transport-layer>" + "            <ip xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-l2l3common\">" + "              <ipv4-mtu>" + maxFrameLen + "</ipv4-mtu>" + "            </ip>" + "          </interface>" + "        </interfaces>" + "      </if>";
                logger.info("MTN FG-Client有保护源宿激活proActXml6为：{}", proActXml6);
                isSend = deviceManager.editConfig(proActXml6, "merge");
                logger.info("isSend===================================================" + isSend);

                String proActXml7 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "        <interfaces>" + "          <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "            <name>flexe-tunnel" + singleEvthName + "</name>" + "            <type>FLEXE-TUNNEL</type>" + "            <pdcn-cfg xmlns=\"http://fiberhome.com/fhnw/yang/systemmanage/fos-dcn\">" + "              <enable>disable</enable>" + "            </pdcn-cfg>" + "          </interface>" + "        </interfaces>" + "      </if>";
                logger.info("MTN FG-Client有保护源宿激活proActXml7为：{}", proActXml7);
                isSend = deviceManager.editConfig(proActXml7, "merge");
                logger.info("isSend===================================================" + isSend);
                //veth口使能
                String proActXml8 = "<mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" + "        <mpls-te>" + "          <interface>" + "            <ifname>flexe-tunnel" + singleEvthName + "</ifname>" + "          </interface>" + "        </mpls-te>" + "      </mpls>";
                logger.info("MTN FG-Client有保护源宿激活proActXml8为：{}", proActXml8);
                isSend = deviceManager.editConfig(proActXml8, "merge");
                logger.info("isSend===================================================" + isSend);
            } else {
                //源宿 去激活
                //mpls使能
                String xml1 = "<mpls xmlns=\"http://fiberhome.com/fhnw/yang/mplsprotocol/fos-mpls\">" +
                        "<mpls-te>" +
                        "<interface nc:operation=\"remove\">" +
                        "<ifname>flexe-tunnel" + singleEvthName + "</ifname>" +//与mpls tunnel保持一致
                        "</interface>" +
                        "</mpls-te>" +
                        "</mpls>";
                logger.info("MTN FG-Client去激活xml1为：{}", xml1);
                isSend = deviceManager.editConfig(xml1, "merge");
                logger.info("MTN FG-Client去激活xml1-isSend===================================================" + isSend);
                String xml2 = " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                        "<interfaces>" +
                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                        "<name>flexe-tunnel" + singleEvthName + "</name>" +
                        "<type>FLEXE-TUNNEL</type>" +
                        "<pdcn-cfg xmlns=\"http://fiberhome.com/fhnw/yang/systemmanage/fos-dcn\" nc:operation=\"remove\"/>" +
                        "</interface>" +
                        "</interfaces>" + "</if>";
                logger.info("MTN FG-Client去激活xml2为：{}", xml2);
                isSend = deviceManager.editConfig(xml2, "merge");
                logger.info("isSend2===================================================" + isSend);
                String xml3 = " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                        "<interfaces>" +
                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
                        "<name>flexe-tunnel" + singleEvthName + "</name>" +
                        "<type>FLEXE-TUNNEL</type>" +
                        "</interface>" +
                        "</interfaces>" +
                        "</if>";
                logger.info("MTN FG-Client去激活xml3为：{}", xml3);
                isSend = deviceManager.editConfig(xml3, "merge");
                logger.info("isSend2===================================================" + isSend);
                String xml4 = " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                        "<interfaces>" +
                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" +
                        "<name>flexe-tunnel" + singleEvthName + "</name>" +
                        "<type>FLEXE-TUNNEL</type>" +
                        "</interface>" +
                        "</interfaces>" +
                        "</if>";
                logger.info("MTN FG-Client去激活xml4为：{}", xml4);
                isSend = deviceManager.editConfig(xml4, "merge");
                logger.info("isSend4===================================================" + isSend);
                workFgName = subclientList.get(0).getClientPortName().split("XGE/mtn-fgclient")[1];
                //去激活oam
                String oamWorkXml = " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" +
                        "<interfaces>" +
                        "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" +
                        "<name>mtn-fgclient" + workFgName + "</name>" +
                        "<type>MTN-FGCLIENT</type>" +
                        "<flexe-oam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-flexeoam\" nc:operation=\"remove\"/>" +
                        "</interface>" +
                        "</interfaces>" +
                        "</if>";
                logger.info("MTN FG-Client去激活oamWorkXml为：{}", oamWorkXml);
                isSend = deviceManager.editConfig(oamWorkXml, "merge");
                logger.info("isSend4===================================================" + isSend);
                proFgName = subclientList.get(1).getClientPortName().split("XGE/mtn-fgclient")[1];
                String oamProXml = " <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "<interfaces>" + "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" + "<name>mtn-fgclient" + proFgName + "</name>" + "<type>MTN-FGCLIENT</type>" + "<flexe-oam xmlns=\"http://fiberhome.com/fhnw/yang/oam/fos-flexeoam\" nc:operation=\"remove\"/>" + "</interface>" + "</interfaces>" + "</if>";
                logger.info("MTN FG-Client去激活oamProXml为：{}", oamProXml);
                isSend = deviceManager.editConfig(oamProXml, "merge");
                logger.info("isSend4===================================================" + isSend);

                //与上面的oam clienNum对应

                String xml6_1 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "<interfaces>" + "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" + "<name>mtn-fgclient" + workFgName + "</name>" +//端口名采用mtn-fgcient加序号的形式  取路由表端口名称
                        "<type>MTN-FGCLIENT</type>" +//端口类型
                        "</interface>" + "</interfaces>" + "</if>";
                logger.info("MTN FG-Client去激活xml5为：{}", xml6_1);
                isSend = deviceManager.editConfig(xml6_1, "merge");
                logger.info("isSend5===================================================" + isSend);

                String xml6_2 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "<interfaces>" + "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" + "<name>mtn-fgclient" + proFgName + "</name>" +//端口名采用mtn-fgcient加序号的形式  取路由表端口名称
                        "<type>MTN-FGCLIENT</type>" +//端口类型
                        "</interface>" + "</interfaces>" + "</if>";
                logger.info("MTN FG-Client去激活xml5为：{}", xml6_2);
                isSend = deviceManager.editConfig(xml6_2, "merge");
                logger.info("isSend5===================================================" + isSend);
            }
        } else {
            //过站  tunnel取fgclient口
            //1：busi_mtn_channel拿到channel主键  查询到开始网元（单设备）start_element  默认start
            BusiMtnChannelRouteTable busiMtnChannelRouteTable = new BusiMtnChannelRouteTable();
            busiMtnChannelRouteTable.setMtnChannelId(mtnclientFg.getMtnChannelId());
            busiMtnChannelRouteTable.setElementId(mtnclientFg.getElementId());
            busiMtnChannelRouteTable.setRouteDirection("1");//默认正向
            //结果应该有四条  工作两条  保护两条
            List<BusiMtnChannelRouteListVoTable> routeInfos = busiMtnChannelRouteTableService.selectBusiMtnChannelRouteTableList(busiMtnChannelRouteTable);
            //获取路由信息取portName、和时隙粒度

            //获取fgclient信息
            ElementBusiMtnclientFg elementBusiMtnclientFg = new ElementBusiMtnclientFg();
            elementBusiMtnclientFg.setMtnChannelId(mtnclientFg.getMtnChannelId());
            elementBusiMtnclientFg.setElementId(mtnclientFg.getElementId());
            //正常有2条 工作 保护
            List<ElementBusiMtnclientFgVo> elementBusiMtnclientFgs = elementBusiMtnclientFgService.selectElementBusiMtnclientFgList(elementBusiMtnclientFg);

            //工作两条路由
            BusiMtnChannelSubclient subclient = new BusiMtnChannelSubclient();
            subclient.setMtnChannelId(mtnclientFg.getMtnChannelId());
            //按照创建时间升序  2条  工作
            subclient.setFgClientId(elementBusiMtnclientFgs.get(0).getId());
            //过站此时只有一条数据
            List<BusiMtnChannelSubclient> workSubclientList = busiMtnChannelSubclientService.selectBusiMtnChannelSubclientList(subclient);

            //保护两条路由
            List<BusiMtnChannelRouteListVoTable> proRouteInfos = routeInfos.stream().filter(routeInfo -> "2".equals(routeInfo.getRouteType())).collect(Collectors.toList());
            //按照创建时间升序  2条  保护
            subclient.setFgClientId(elementBusiMtnclientFgs.get(1).getId());
            //过站此时只有一条数据
            List<BusiMtnChannelSubclient> proSubclientList = busiMtnChannelSubclientService.selectBusiMtnChannelSubclientList(subclient);

            List<BusiMtnChannelSubclient> finalSubClients = new ArrayList<>();
            finalSubClients.addAll(workSubclientList);
            finalSubClients.addAll(proSubclientList);
            String workEndPoint1Name = finalSubClients.get(0).getClientPortName().split("XGE/mtn-fgclient")[1];
            String workEndPoint2Name = finalSubClients.get(1).getClientPortName().split("XGE/mtn-fgclient")[1];

            //取cross信息 正常就两条数据
            BusiMtnChannelCross busiMtnChannelCross = new BusiMtnChannelCross();
            busiMtnChannelCross.setMtnChannelId(mtnclientFg.getMtnChannelId());
            busiMtnChannelCross.setOrder("asc");
            List<BusiMtnChannelCrossListVo> busiMtnChannelCrossListVos = busiMtnChannelCrossService.selectBusiMtnChannelCrossList(busiMtnChannelCross);


            //激活
            if ("1".equals(busiMtnChannelXmlVo.getStatus())) {
                //===============================================处理工作过站激活====================================
                if (!CollectionUtils.isEmpty(proRouteInfos)) {
                    //正常2条结果
                    for (int i = 0; i < proRouteInfos.size(); i++) {
                        ElementPortMode elementPortMode = elementPortModeService.selectElementPortModeById(proRouteInfos.get(i).getPortId());
                        String portName = elementPortMode.getPortName();
                        String timeSlot = finalSubClients.get(i).getTimeSlot();
                        String fgClientName = finalSubClients.get(i).getClientPortName().split("XGE/mtn-fgclient")[1];
                        String fgClientNum = finalSubClients.get(i).getFgClientNum();

                        String actCrossXml = "  <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "        <interfaces>" + "          <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "            <name>mtn-fgclient" + fgClientName + "</name>" +//端口名采用mtn-fgcient加序号的形式
                                "            <type>MTN-FGCLIENT</type>" +//端口类型
                                "            <mtn-fgclient-ctrlinterface xmlns=\"http://fiberhome.com/fhnw/yang/interface/mtninterface/fos-mtnif-fgclientctrl\">" + "              <work-mode>transparent</work-mode>" +//工作模式：过站取值transparent，源宿取值terminate
                                "              <fgclient-num>" + fgClientNum + "</fgclient-num>" +//MTN FGClient Num配置,取值范围1-65534，要求同一条小颗粒业务两端fg Client Num相同
                                "              <fgclient-timeslot>" + "                <if-name>" + portName + "</if-name>" +//关键字，时隙成员接口
                                "                <fg-timeslot-str>" + timeSlot + "</fg-timeslot-str>" +//fg client时隙配置，必选，字符串配置格式0-1,3-4,6 时隙从0开始编号
                                "              </fgclient-timeslot>" + "            </mtn-fgclient-ctrlinterface>" + "          </interface>" + "        </interfaces>" + "      </if>";
                        logger.info("MTN FG-Client过站激活actCrossXml为：{}", actCrossXml);
                        isSend = deviceManager.editConfig(actCrossXml, "merge");
                        logger.info("isSend===================================================" + isSend);

                    }
                    //===============================================tunnel====================================
                    for (int i = 0; i < finalSubClients.size(); i++) {
                        String[] mtntunnels = finalSubClients.get(i).getClientPortName().split("XGE/mtn-fgclient");
                        String actCrossXml2 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "<interfaces>" + "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "<name>flexe-tunnel" + mtntunnels[1] + "</name>" +//flexe-tunnel加上序号
                                "<type>FLEXE-TUNNEL</type>" + "<flexetunnel-ctrlinterface xmlns=\"http://fiberhome.com/fhnw/yang/interface/flexeinterface/fos-flexeif-tunnel\">" + "<protect-type>flexe-1p1</protect-type>";
                        if ("1".equals(finalSubClients.get(i).getClientType())) {
                            actCrossXml2 += "<work-flexe-client>mtn-fgclient" + mtntunnels[1] + "</work-flexe-client>";

                        } else {
                            actCrossXml2 += "<protect-flexe-client>mtn-fgclient" + mtntunnels[1] + "</protect-flexe-client>";
                        }
                        actCrossXml2 += "</flexetunnel-ctrlinterface>" + "</interface>" + "</interfaces>" + "</if>";
                        logger.info("MTN FG-Client工作过站激活actCrossXml2为：{}", actCrossXml2);
                        isSend = deviceManager.editConfig(actCrossXml2, "merge");
                        logger.info("isSend===================================================" + isSend);
                    }
                    //===============================================cross====================================


                    String actCrossXml3 = "  <flexexc xmlns=\"http://fiberhome.com/fhnw/yang/transmissionservice/fos-flexeconnection\">" + "    <cross-connects>" + "      <cross-connect>" + "        <cross-connect-name>" + busiMtnChannelCrossListVos.get(0).getCrossName() + "</cross-connect-name>" + "        <endpoint1-name>flexe-tunnel" + workEndPoint1Name + "</endpoint1-name>" + "        <endpoint2-name>flexe-tunnel" + workEndPoint2Name + "</endpoint2-name>" + "      </cross-connect>" + "    </cross-connects>" + "  </flexexc>";
                    logger.info("MTN FG-Client过站激活actCrossXml3为：{}", actCrossXml3);
                    isSend = deviceManager.editConfig(actCrossXml3, "merge");
                    logger.info("isSend===================================================" + isSend);
                }

            } else {
                //去激活
                //===============================================处理工作过站去激活====================================
                String inActCrossXml1 = "<flexexc xmlns=\"http://fiberhome.com/fhnw/yang/transmissionservice/fos-flexeconnection\">" + "    <cross-connects>" + "      <cross-connect nc:operation=\"remove\">" + "        <cross-connect-name>" + busiMtnChannelCrossListVos.get(0).getCrossName() + "</cross-connect-name>" + "        <endpoint1-name>flexe-tunnel" + workEndPoint1Name + "</endpoint1-name>" + "        <endpoint2-name>flexe-tunnel" + workEndPoint2Name + "</endpoint2-name>" + "      </cross-connect>" + "    </cross-connects>" + "  </flexexc>";
                logger.info("MTN FG-Client过站去激活actCrossXml1为：{}", inActCrossXml1);
                isSend = deviceManager.editConfig(inActCrossXml1, "merge");
                logger.info("isSend===================================================" + isSend);

                //===============================================tunnel====================================
                for (int j = 0; j < finalSubClients.size(); j++) {
                    String[] mtntunnels = finalSubClients.get(j).getClientPortName().split("XGE/mtn-fgclient");
                    String inActCrossXml2 = "<if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "<interfaces>" + "<interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" nc:operation=\"remove\">" + "<name>flexe-tunnel" + mtntunnels[1] + "</name>" +//flexe-tunnel加上序号
                            "<type>FLEXE-TUNNEL</type>" + "</interface>" + "</interfaces>" + "</if>";
                    logger.info("MTN FG-Client过站去激活actCrossXml2为：{}", inActCrossXml2);
                    isSend = deviceManager.editConfig(inActCrossXml2, "merge");
                    logger.info("isSend===================================================" + isSend);
                }
                for (int j = 0; j < finalSubClients.size(); j++) {
                    String[] mtntunnels = finalSubClients.get(j).getClientPortName().split("XGE/mtn-fgclient");
                    String inActCrossXml4 = "  <if xmlns=\"http://fiberhome.com/fhnw/yang/interface/fos-interface-common\">" + "        <interfaces>" + "          <interface xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "            <name>mtn-fgclient" + mtntunnels[1] + "</name>" +//端口名采用mtn-fgcient加序号的形式
                            "            <type>MTN-FGCLIENT</type>" +//端口类型
                            "          </interface>" + "        </interfaces>" + "      </if>";
                    isSend = deviceManager.editConfig(inActCrossXml4, "merge");
                    logger.info("MTN FG-Client过站去激活actCrossXml4为：{}", inActCrossXml4);
                    logger.info("isSend===================================================" + isSend);
                }
            }
        }
        return isSend;
    }

}
